#include <gtk/gtk.h>
#include <libintl.h>
#include <locale.h>
#include <glib/gi18n.h>	//include _

#include <stdlib.h>

#define PACKAGE "main"
#define LOCALEDIR "./locale"

static GtkWidget *entry = NULL;

void on_button_clicked(GtkWidget *button, gpointer data)
{
    gtk_entry_set_text(GTK_ENTRY(entry), _("this text will put in the entry"));
}

int main(int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *button;
    GtkWidget *label;

    char *ret;
//    putenv("LANG=zh_CN.UTF-8");
    //putenv("LANGUAGE=zh_CN.UTF-8");
    ret = setlocale(LC_ALL, "");
    g_message("setlocale: %s", ret);
    //setlocale (LC_ALL, "zh_CN.UTF-8");
    ret = bindtextdomain(PACKAGE, LOCALEDIR);
    g_message("bindtextdomain: %s", ret);
    ret = textdomain(PACKAGE);     //pass .mo
    g_message("textdomain: %s", ret);

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtk_main_quit), NULL);
    gtk_window_set_title(GTK_WINDOW(window), _("window"));
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 10);

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(window), vbox);

    label = gtk_label_new(_("this is a international application"));
    gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);

    button = gtk_button_new_with_label(_("new button"));
    gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 5);
    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(on_button_clicked), NULL);

    g_message(_("new button"));

    entry = gtk_entry_new();
    gtk_box_pack_start(GTK_BOX(vbox), entry, FALSE, FALSE, 5);

    gtk_widget_show_all(window);
    gtk_main();
    return TRUE;
}

